#[tauri::command]
async fn handle_git_url(url: String) -> Result<(), String> {
    let downloader_path = std::env::current_exe()
        .unwrap()
        .parent()
        .unwrap()
        .join("downloader");
    
    let output = Command::new(downloader_path)
        .arg("--url")
        .arg(url)
        .spawn()
        .map_err(|e| e.to_string())?;

    Ok(())
}

// 注册自定义协议处理
#[cfg(target_os = "windows")]
fn register_protocol() {
    use winreg::{RegKey, enums::*};
    let hkcr = RegKey::predef(HKEY_CLASSES_ROOT);
    let (key, _) = hkcr.create_subkey("gitdown").unwrap();
    key.set_value("URL Protocol", &"").unwrap();
}

// 剪贴板监听线程
fn clipboard_listener() {
    use clipboard::{ClipboardContext, ClipboardProvider};
    let mut ctx = ClipboardContext::new().unwrap();
    let mut last_content = String::new();
    
    loop {
        let content = ctx.get_contents().unwrap_or_default();
        if content != last_content && is_git_url(&content) {
            window.emit("clipboard-change", content.clone()).unwrap();
            last_content = content;
        }
        std::thread::sleep(Duration::from_secs(1));
    }
}